home *** CD-ROM | disk | FTP | other *** search
- /* access.c, from page 350 of Turbo C Bible */
- #include<stdio.h>
- #include<io.h>
- char filename [] = "c:\\config.sys";
- main ()
- {
- FILE *infile;
- char buffer [80];
- /* Check if the file exists. Note that
- we need two '\' */
- if (access(filename, 4) == -1)
- {
- perror ("access failed");
- exit (1);
- }
- if ((infile = fopen (filename, "r")) == NULL)
- {
- perror ("fopen failed");
- exit (1);
- }
- printf ("Contents of %s\n", filename);
- while (fgets (buffer, 80, infile) != NULL)
- {
- printf (buffer);
- }
- }